package viewer;

import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;

public class RoffPostScriptPanel extends JPanel {

    JComboBox selectionList;
    JRadioButton useBG;
    JRadioButton noUseBG;
    JRadioButton grayscaleButton;
    JRadioButton colorButton;
    JTextField resolutionField;

    public RoffPostScriptPanel(int options, int resolution) {

        this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

        JPanel panel = new JPanel();
        panel.setLayout(new GridLayout(0, 1));
        panel.setBorder(BorderFactory.createTitledBorder(
                        BorderFactory.createEtchedBorder(),
                        "Output In"
                        ));
        ButtonGroup bg = new ButtonGroup();
        colorButton = new JRadioButton("Color", RoffViewPanel.PS_GRAY != (options & RoffViewPanel.PS_GRAY));
        grayscaleButton = new JRadioButton("Grayscale", RoffViewPanel.PS_GRAY == (options & RoffViewPanel.PS_GRAY));
        bg.add(colorButton);
        bg.add(grayscaleButton);
        panel.add(colorButton);
        panel.add(grayscaleButton);
        this.add(panel);
        this.add(Box.createVerticalStrut(5));

        panel = new JPanel();
        panel.setLayout(new GridLayout(0, 1));
        panel.setBorder(BorderFactory.createTitledBorder(
                        BorderFactory.createEtchedBorder(),
                        "Include Background"
                        ));
        bg = new ButtonGroup();
        noUseBG = new JRadioButton("No", RoffViewPanel.PS_NOBG == (options & RoffViewPanel.PS_NOBG));
        useBG = new JRadioButton("Yes", RoffViewPanel.PS_NOBG != (options & RoffViewPanel.PS_NOBG));
        bg.add(noUseBG);
        bg.add(useBG);
        panel.add(noUseBG);
        panel.add(useBG);
        this.add(panel);
        this.add(Box.createVerticalStrut(5));

        panel = new JPanel();
        panel.setLayout(new GridLayout(0, 1));
        panel.setBorder(BorderFactory.createTitledBorder(
                        BorderFactory.createEtchedBorder(),
                        "Internal Resolution"
                        ));
        resolutionField = new JTextField("" + resolution, 10);
        panel.add(resolutionField);
        this.add(panel);
    }

    public int getOptions() {
        int rval = 0;
        if (noUseBG.isSelected()) {
            rval += RoffViewPanel.PS_NOBG;
        }
        if (grayscaleButton.isSelected()) {
            rval += RoffViewPanel.PS_GRAY;
        }
        return rval;
    }

    public int getResolution() {
        int rval = 1000;
        try {
            rval = Integer.parseInt(resolutionField.getText());
        } catch (Exception e) {
            rval = 1000;
        }
        return rval;
    }
}